import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model - CA证书管理
 * @date: 2019/9/10
 */
import { createPagination, getResponse } from 'utils/utils';
import { queryList as _queryList, deleteCa as _deleteCa } from "../services/caManagementService";
export default {
  namespace: 'caManagement',
  state: {
    list: {
      dataSource: [],
      // 证书列表
      pagination: {} // 证书分页

    }
  },
  effects: {
    // 查询证书列表
    queryList: /*#__PURE__*/_regeneratorRuntime.mark(function queryList(_ref, _ref2) {
      var payload, call, put, res, response;
      return _regeneratorRuntime.wrap(function queryList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(_queryList, payload);

            case 4:
              res = _context.sent;
              response = getResponse(res);

              if (!response) {
                _context.next = 9;
                break;
              }

              _context.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  list: {
                    dataSource: response.content || [],
                    pagination: createPagination(response)
                  }
                }
              });

            case 9:
            case "end":
              return _context.stop();
          }
        }
      }, queryList);
    }),
    // 删除证书
    deleteCa: /*#__PURE__*/_regeneratorRuntime.mark(function deleteCa(_ref3, _ref4) {
      var payload, call, res, response;
      return _regeneratorRuntime.wrap(function deleteCa$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(_deleteCa, payload);

            case 4:
              res = _context2.sent;
              response = getResponse(res);
              return _context2.abrupt("return", response);

            case 7:
            case "end":
              return _context2.stop();
          }
        }
      }, deleteCa);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref5) {
      var payload = _ref5.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};